﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace UtilLib
{
    public static class StringUtil
    {

        /// <summary>
        /// Inserts the split string into string.
        /// </summary>
        /// <param name="original">The original string.</param>
        /// <param name="splitString">The split string.</param>
        /// <param name="splitIndex">Index of the split.</param>
        /// <returns></returns>
        public static string InsertSplitString(string original, string splitString, int splitIndex)
        {
            if (original.Length > splitIndex)
            {
                return original.Insert(splitIndex, splitString);
            }
            return original;
        }

        /// <summary>
        /// Deletes the split string from string.
        /// </summary>
        /// <param name="original">The original string.</param>
        /// <param name="splitIndex">Index of the split.</param>
        /// <returns></returns>
        public static string DeleteSplitString(string original, int splitIndex)
        {
            if (original.Length > splitIndex)
            {
                return original.Remove(splitIndex, 1);
            }
            return original;
        }

        /// <summary>
        /// Returns whether a string is null, empty, or whitespace. Same implementation as in String.IsNullOrWhitespace in .Net 4.0
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static bool IsNullOrWhitespace(string value)
        {
            return ((value == null) || (value.Trim().Length == 0));
        }
    }
}
